

const koaBody = require('koa-body'); //解析上传文件的插件
const router = require('./router.js');
const cors = require('koa2-cors'); // 跨域
const Koa = require('koa')
const logger = require('koa-logger');
const sslify = require('koa-sslify').default;
const https = require('https');
const fs = require('fs')

const app = new Koa();
app.use(sslify())
app.use(logger())
app.use(koaBody({
    multipart: true,
    formidable: {
        maxFileSize: 2000 * 1024 * 1024    // 设置上传文件大小最大限制，默认2M
    }
}))
.use(cors({
    origin: function (ctx) {
        return '*';
    },
    exposeHeaders: ['WWW-Authenticate', 'Server-Authorization'],
    maxAge: 5,
    credentials: true,
    allowMethods: ['GET', 'POST', 'DELETE'],
    allowHeaders: ['Content-Type', 'Authorization', 'Accept'],
}))


var options = {
    key: fs.readFileSync('./privatekey.pem'),  //ssl文件路径
    cert: fs.readFileSync('./certificate.pem')  //ssl文件路径
};
app.use(router.routes())
    .use(router.allowedMethods());

https.createServer(options, app.callback()).listen(9527, () => {
    console.log(`server running success at 9527`)
});
